<template>
<div class="container">
  <van-nav-bar
      title="添加地址"
      left-text="返回"
      left-arrow
      fixed
      @click-left="goBack"
  />
<div class="form">
  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
          v-model="buyPeople"
          name="姓名"
          label="姓名"
          placeholder="姓名"
          :rules="[{ required: true, message: '请填写姓名' }]"
      />
      <van-field
          v-model="telephone"
          name="电话"
          label="电话"
          placeholder="电话"
          :rules="[{ required: true, message: '请填写电话' }]"
      />
      <van-field
          v-model="address"
          name="地址"
          label="地址"
          placeholder="地址"
          :rules="[{ required: true, message: '请填写地址' }]"
      />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>

</div>
</div>
</template>

<script>
import {Toast} from "vant";

export default {
  name: "Address",
  data(){
    return{
      address:'',
      buyPeople:'',
      telephone:''
    }
  },
  methods:{
    onSubmit(){

      let data={
        selected:true,
        user_id:Number(localStorage.getItem('user_id')),
        telephone:this.telephone,
        address:this.address,
        buyPeople:this.buyPeople
      }
      this.$http.post('address',data).then(()=>{
        Toast.success('添加成功');
        setTimeout(()=>{this.$router.back()},1500)
      })

    },
    goBack() {
      this.$router.back()
    },
  }
}
</script>

<style scoped lang="less">
.container{
  padding-top: 50px;
}
</style>
